package com.cet.designpatterns.principle.singleresponsibility;

/**
 * @program: algorithm
 * @description: 单一职责原则
 * @author: 陈恩涛
 * @create: 2021-08-25 16:18
 **/
public class SingleResponsibility02 {
    public static void main(String[] args) {
        new RoadVehicle().run("摩托车");
        new AirVehicle().run("飞机");
        new WaterVehicle().run("轮船");
    }
}

/*
*
* 方案2的分析
* 1、遵守了单一职责原则
* 2、改动很大，既要将类分解，同时修客户端
* 3、改进：直接修改Vehicle，改动的代码比较少
* */

class RoadVehicle{
    public void run(String vehicle) {
        System.out.println(vehicle + "在公路上行驶……");
    }
}

class AirVehicle{
    public void run(String vehicle) {
        System.out.println(vehicle + "在天上飞行……");
    }
}

class WaterVehicle{
    public void run(String vehicle) {
        System.out.println(vehicle + "在水面行驶……");
    }
}
